package com.bkgy.controller.optimize.controller;

import com.bkgy.controller.optimize.entity.*;
import com.bkgy.controller.optimize.service.OptimizeService;
import com.bkgy.sys.common.entity.ResultData;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * Author:Lipeng Zhao
 * Description:
 *
 * @Date:Created In 10:58 2025/5/6
 */
@Controller
@RequestMapping("/optimize")
public class OptimizeController {

    @Autowired
    private OptimizeService optimizeService;

    @PostMapping("/findData")
    @ResponseBody
    public ResultData findData(@RequestBody AcidRollingProductRequest request) {
        return optimizeService.findMapByCondition(request);
    }

    @PostMapping("/findAcidRollingProduct")
    @ResponseBody
    public ResultData findAcidRollingProduct(@RequestBody AcidRollingProductRequest request) {
        return optimizeService.findAcidRollingProduct(request);
    }

    @GetMapping("acidRollingProduct/export")
    public ModelAndView acidRollingProductExport(String volumeNum, String steelGrade, String inletWidth, String entryThickness, String startDate, String endDate) {
        Map<String, Object> map = new HashMap<>();
        map.put("volumeNum", volumeNum);
        map.put("steelGrade", steelGrade);
        map.put("inletWidth", inletWidth);
        map.put("entryThickness", entryThickness);
        map.put("startDate", startDate);
        map.put("endDate", endDate);
        return optimizeService.acidRollingProductExport(map);
    }

    @PostMapping("/findCaseData")
    @ResponseBody
    public ResultData findCaseData(@RequestBody AcidRollingProductRequest request) {
        return optimizeService.findCaseMapByCondition(request);
    }

    @PostMapping("/findCase")
    @ResponseBody
    public ResultData findCase(@RequestBody AcidRollingProductRequest request) {
        return optimizeService.findCaseByCoilNo(request);
    }

    @PostMapping("/deleteCase")
    @ResponseBody
    public ResultData deleteCase(@RequestBody AcidRollingProductRequest request) {
        return optimizeService.deleteCaseByCoilNo(request);
    }

    @PostMapping("/updateCase")
    @ResponseBody
    public ResultData updateCase(@RequestBody CaseManageEntity request) {
        return optimizeService.updateCase(request);
    }

    @PostMapping("acidRolling/import/data")
    @ResponseBody
    public ResultData importData(@RequestParam(value = "file") MultipartFile file) {
        Map<String, Object> map = new HashMap<>();
        map.put("file", file);
        return optimizeService.importData(map);
    }

    @GetMapping("acidRolling/export/template")
    public ModelAndView exportTemplate() {
        Map<String, Object> map = new HashMap<>();
        return optimizeService.exportTemplate(map);
    }

    @PostMapping("acidRolling/simulationReport")
    @ResponseBody
    public ResultData simulationReport(@RequestBody SimulationReportRequest request) {
        return optimizeService.simulationReport(request);
    }

    @PostMapping("acidRolling/classStatistics")
    @ResponseBody
    public ResultData classStatistics(@RequestBody ClassStatisticsReq request) {
        return optimizeService.classStatistics(request);
    }

    @PostMapping("acidRolling/findByYpClass")
    @ResponseBody
    public ResultData findByYpClass(@RequestBody ClassStatisticsReq request) {
        return optimizeService.findByYpClass(request);
    }

    @GetMapping("acidRolling/classStatistics/export")
    public ModelAndView classStatisticsExport(int ypClass, int widthClass, String thicknessClass, String startDate, String endDate) {
        Map<String, Object> map = new HashMap<>();
        map.put("ypClass", ypClass);
        map.put("widthClass", widthClass);
        map.put("thicknessClass", thicknessClass);
        map.put("startDate", startDate);
        map.put("endDate", endDate);
        return optimizeService.classStatisticsExport(map);
    }

    @GetMapping("/distributionData")
    @ResponseBody
    public ResultData distributionData() {
        return optimizeService.distributionData();
    }

    @PostMapping("/findLoadDistributionData")
    @ResponseBody
    public ResultData findCaseData(@RequestBody LoadDistributionRequest request) {
        return optimizeService.findLoadDistributionMapByCondition(request);
    }

    @PostMapping("/findLoadDistributionCurveData")
    @ResponseBody
    public ResultData findLoadDistributionCurveData(@RequestBody LoadDistributionRequest request) {
        return optimizeService.findLoadDistributionCurveData(request);
    }

    @Operation(summary = "负荷分配优化导出", description = "负荷分配优化导出")
    @PostMapping("/exportLoadDistributionXlsx")
    public void classStatisticsExport(@RequestBody LoadDistributionRequest loadDistributionRequest, HttpServletResponse response) {
        optimizeService.loadDistributionExport(loadDistributionRequest, response);
    }
}
